using System;
using CdcSoftware.Pivotal.Applications.Core.Common;
using CdcSoftware.Pivotal.Applications.Core.Server;
using CdcSoftware.Pivotal.Applications.Core.Server.InteractionServices;
using CdcSoftware.Pivotal.Engine;
using CdcSoftware.Pivotal.Engine.Types.ServerTasks;
using System.Data;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using CdcSoftware.Pivotal.Engine.Mail;

namespace Pcm.Retail.Service.ServiceTask
{
    /// <summary>
    /// The Form server task class to undertake some specfic business tasks for a business object
    /// associated with a specified form. It will call service server task to share business
    /// functionality that are not directly related to a form.
    /// </summary>
    /// <history>
    /// #Revision   Date            Author      Description
    /// 6.0.9.1     2011-08-29      DS          Initial version for Retail.
    /// </history>
    public class Wincor : AbstractApplicationServerTask 
    {
        

        #region Public methods

        [TaskExecute]
        public void SendEmailForSSIS(ParameterList parameters)
        {
            try
            {
                string emailFrom = TypeConvert.ToString(parameters[0]);
                string emailTo = TypeConvert.ToString(parameters[1]);
                string emailSubject = TypeConvert.ToString(parameters[2]);
                string emailBody = TypeConvert.ToString(parameters[3]);
                string archiveLocation = TypeConvert.ToString(parameters[4]);
                string fileName = TypeConvert.ToString(parameters[5]);
                string dateTimeComponenet = TypeConvert.ToString(parameters[6]);

                EmailMessage emailMessage = this.SystemServer.CreateMessage();
                
                emailMessage.To.Add(emailTo);
                emailMessage.Subject = emailSubject;
                emailMessage.IsBodyHtml = false;
                emailMessage.Body = emailBody;

                EmailMessageAttachment ema = new EmailMessageAttachment(archiveLocation + "\\" + fileName + dateTimeComponenet + ".txt");
                emailMessage.Attachments.Add(ema);

                emailMessage.Send();


                parameters[0] = "Success";
            }
            catch (Exception exc)
            {
                throw new PivotalApplicationCoreException(exc.Message, exc);
            }
        }

        #endregion
    }
}
